<template>
	<Table border :columns="columns1" :data="data4" :loading="loadTable"></Table>
</template>

<script>
import querystring from 'querystring';
import { HOST } from '../../libs/config.js';
import { loginInvalid } from "../../libs/loginInvalidNotice.js";

export default {
	data() {
		return {
      statusList: [
        '未审核',
        '审核通过',
        '驳回'
      ],
			loadTable: false,
			columns1: [
        {
					title: '所属项目',
          key: 'project_name',
          align: 'center',
					width: 150
				},
				{
					title: '物品名称',
          key: 'goods_name',
          align: 'center',
          
        },
        {
          title: '数量',
          key: 'num',
          align: 'center',
          
        },
        {
          title: '提交时间',
          key: 'time',
          align: 'center',
          render: (h, params) => {
            return h('span', new Date(parseInt(params.row.time) * 1000).toLocaleString());
          }
        },
				{
          title: '状态',
          key: 'status',
					fix: 'right',
					align: 'center',
					render: (h, params) => {
						return h('Tag', {
						  props: {
						    color: this.getColor(params.row.status)
						  },
						}, this.statusList[parseInt(params.row.status)])
					}
				}
			],
			data4: []
		}
	},
	methods: {
		refreshReceivelist() {
			this.loadTable = true;
			this.$axios.get(HOST + '/store/myReceiveTable', {
					withCredentials: true
				})
				.then((response) => {
					this.loadTable = false;

					let data = response.data;
					if (data.length > 0) {
						this.data4 = data;
					}
				})
				.catch((err) => {
					if (err.data.status && err.data.status === 'invalid Token') {
						loginInvalid(this)();
					} else {

					}
				})
		},
    getColor(status) {
      if (status === '0') {
        return 'gray';
      } else if (status ===  '1') {
        return 'green';
      } else {
        return 'red';
      }
    }
	},
	mounted() {
		this.refreshReceivelist();
  }
}
</script>
